<?php
require('phpQuery/phpQuery.php');

// INITIALIZE IT
// phpQuery::newDocumentHTML($markup);
// phpQuery::newDocumentXML();
// phpQuery::newDocumentFileXHTML('test.html');
// phpQuery::newDocumentFilePHP('test.php');
// phpQuery::newDocument('test.xml', 'application/rss+xml');
// this one defaults to text/html in utf8
//$doc = phpQuery::newDocument('<div/>');
//
//// FILL IT
//// array syntax works like ->find() here
//$doc['div']->append('<ul></ul>');
//// array set changes inner html
//$doc['div ul'] = '<li>1</li> <li>2</li> <li>3</li>';

//// MANIPULATE IT
//$li = null;
//// almost everything can be a chain
//$doc['ul > li']
//	->addClass('my-new-class')
//	->filter(':last')
//		->addClass('last-li')
//// save it anywhere in the chain
//		->toReference($li);

// SELECT DOCUMENT
// pq(); is using selected document as default
$str = <<<EOD
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head profile="http://purl.org/NET/erdf/profile">
        <title>PHP: Strings - Manual</title>
        <style type="text/css" media="all">
            @import url("http://static.php.net/www.php.net/styles/site.css");
            @import url("http://static.php.net/www.php.net/styles/phpnet.css");
        </style>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <link rel="shortcut icon" href="http://static.php.net/www.php.net/favicon.ico" />
        <link rel="contents" href="index.php" />
        <link rel="index" href="language.types.php" />
        <link rel="prev" href="language.types.float.php" />
    </head>
    <body>
        <ul id="test" class="test" rel="hai">
            <li e="10">keke</li>
            <li e="20">tete</li>
            <li e="130">ii</li>
            <li e="156">uu</li>
        </ul>
    </body>
</html>
EOD;
$doc = phpQuery::newDocumentHTML($str);

phpQuery::selectDocument($doc);
// documents are selected when created or by above method
// query all unordered lists in last selected document
//$ul = pq('ul')->insertAfter('div');

$ul = pq('ul >li');



$ul = pq('ul li');

foreach($ul as $li) {
	//echo $li->attr('name');
    echo $li->tagName;
	echo pq($li)->attr('e');
} 
die();

// ITERATE IT
// all direct LIs from $ul
foreach($ul['> li'] as $li) {
	// iteration returns PLAIN dom nodes, NOT phpQuery objects
	$tagName = $li->tagName;
	$childNodes = $li->childNodes;
	// so you NEED to wrap it within phpQuery, using pq();
	pq($li)->addClass('my-second-new-class');
}

// PRINT OUTPUT
// 1st way
print phpQuery::getDocument($doc->getDocumentID());
//// 2nd way
//print phpQuery::getDocument(pq('div')->getDocumentID());
//// 3rd way
//print pq('div')->getDocument();
//// 4th way
//print $doc->htmlOuter();
//// 5th way
//print $doc;
//// another...
//print $doc['ul'];